﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WXY.Course.BLL;
using WXY.Course.Model;
using WXY.Course.Web.Areas.Admin.Filter;

namespace WXY.Course.Web.Controllers
{
    public class ResourceController : Controller
    {
        ResourceBLL _resourceBLL = new ResourceBLL();

        public ActionResult List(int moduleId)
        {
            var result = _resourceBLL.GetList(moduleId);
            
            return RedirectToAction("Detail", new { id = result.Count == 0 ? 0 : result.First().Code });
        }

        [ChildActionOnly]
        public ActionResult ChildList(int moduleId)
        {
            var result = _resourceBLL.GetList(moduleId);
            return View(result);
        }

        public ActionResult Detail(int? id)
        {
            if (!id.HasValue)
            {
                return RedirectToAction("Index", "Home");
            }

            ResourceInfo info = _resourceBLL.Get(id.Value);
            if (info == null)
            {
                return RedirectToAction("Index", "Home");
            }
            return View(info);
        }
    }
}
